﻿Public Class MuhOdemeGirisi : Inherits Process

	Dim WithEvents Grid As Grid
	Dim WithEvents Errors As Grid

	Public Overrides Sub GenericEvent(ByVal e As ProcessEventArgs)
		Select Case e.EventType
			Case EventType.Initialize
				Start("Ödeme girişi", "Ödeme bilgilerini girin.")
				AddList()
				Grid = List
				List.AddColumns("durum(;24l),*tarih(Tarih;90d),*kimlik(Kimlik no.;80l),*kime(Kime;100%l),*tutar(Tutar;80m)")
				'Errors = AddList("Errors", 0, 120)
				Errors.AddColumns("durum(;24l),sira(;40c),aciklama(Açıklamalar;100%l)")
			Case EventType.Shown
				Grid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
				Grid.DefaultCellStyle.Padding = New Padding(3, 2, 3, 2)
				Grid.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
				Grid.ShowLineNumbers = True
				AddRow()
			Case EventType.ValidateForm
				AddRow()
				Buttons.Show("Save.Reset")
				e.Result = True
		End Select
	End Sub

	Function AddRow() As DataGridViewRow
		Grid.Rows.Add()
		Grid.CurrentCell = Grid.Rows(Grid.Rows.Count - 1).Cells("tarih")
		Return Grid.Rows(Grid.Rows.Count - 1)
	End Function

	Function ShowResults(tur As String, Value As Object, Row As DataGridViewRow) As Boolean
		If tur = "kimlik" Then
			Rs = Sigortali.KimlikAra(Remote, Value)
		End If
		Row.Cells("kime").Value = ""
		If Not Rs.EOF Then
			Row.Cells("kime").Value = Trim(Rs("adi")) & " " & Trim(Rs("soyadi"))
		End If
		CheckRow(Row)
		Return Not Rs.EOF
	End Function

	Private Sub Grid_CellValidating(sender As Object, e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles Grid.CellValidating
		Dim Row = Grid.Rows(Grid.CurrentCell.RowIndex)
		Dim Col = Grid.Columns(Grid.CurrentCell.ColumnIndex)
		Dim Cell = Row.Cells(Col.Name)
		If Not Grid.IsCurrentCellDirty Then Return
		Select Case Col.Name
			Case "kimlik"
				ShowResults("kimlik", Grid.EditingControl.Text, Row)
		End Select
	End Sub

	Private Sub Grid_Propegate(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Grid.Propegate
		e.Handled = True
		Dim Row = Grid.Rows(Grid.CurrentCell.RowIndex)
		Dim Col = Grid.Columns(Grid.CurrentCell.ColumnIndex)
		Dim Cell = Row.Cells(Col.Name)
		Select Case Col.Name
			Case "tarih" : Grid.CurrentCell = Row.Cells("kimlik")
			Case "kimlik" : Grid.CurrentCell = Row.Cells("kime")
			Case "kime" : Grid.CurrentCell = Row.Cells("tutar")
			Case "tutar" : If Row.Index = Grid.Rows.Count - 1 Then AddRow() Else Grid.CurrentCell = Grid.Rows(Row.Index + 1).Cells("tarih")
		End Select
	End Sub

	'Private Sub Errors_GenericEvent(Sender As Object, EventType As GenericEventType, Param As String) Handles Errors.GenericEvent
	'	If EventType = GenericEventType.Activate Then
	'		'Dim Row = List.Rows(Errors.SelectedRow("sira") - 1)
	'		Grid.ClearSelection()
	'		Grid.CurrentCell = Nothing
	'		'Row.Selected = True
	'		'Grid.CurrentCell = Row.Cells("kimlik")
	'		Grid.Focus()
	'	End If
	'End Sub

	Private Sub SetError(Row As DataGridViewRow, Icon As String, Message As String)
		Row.Cells("durum").Value = "[" & Icon & "]"
		Errors.AddRow(Row.Cells("durum").Value, Row.Cells("sira").Value, Message)
	End Sub

	Private Sub CheckRow(Row As DataGridViewRow)
	End Sub

	Private Sub Grid_RowValidating(sender As Object, e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles Grid.RowValidating
		If Not Grid.IsCurrentRowDirty Then Return
		CheckRow(Grid.Rows(e.RowIndex))
	End Sub

End Class

